package leetcode.code116.PopulatingNextRightPointersinEachNode;

import leetcode.helper.HelpDebug;
import leetcode.helper.tree.Node;
import leetcode.helper.tree.NodeArray;

public abstract class PopulatingNextRightPointersinEachNode implements IPopulatingNextRightPointersinEachNode {

	@Override
	public void debug1() {
//	输入：root = [1,2,3,4,5,6,7]
//	输出：[1,#,2,3,#,4,5,6,7,#]
//	解释：给定二叉树如图 A 所示，你的函数应该填充它的每个 next 指针，以指向其下一个右侧节点，如图 B 所示。序列化的输出按层序遍历排列，同一层节点由 next 指针连接，'#' 标志着每一层的结束。
		Integer[] root = new Integer[] { 1, 2, 3, 4, 5, 6, 7 };
		Node input = NodeArray.array2tree(root);
		String expect = "1,#,2,3,#,4,5,6,7,#";
		HelpDebug.printInputs(expect, new Object[] { root });
		Node res = this.debug(input);
		HelpDebug.printObject(NodeArray.perfecttTree2array(res));
	}

	@Override
	public void debug2() {
		Integer[] root = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
		Node input = NodeArray.array2tree(root);
		String expect = "1,#,2,3,#,4,5,6,7,#,8,9,10,11,12,13,14,15,#";
		HelpDebug.printInputs(expect, new Object[] { root });
		Node res = this.debug(input);
		HelpDebug.printObject(NodeArray.perfecttTree2array(res));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	abstract public Node connect(Node root);

	@Override
	public Node debug(Node root) {
		Node node = this.connect(root);
		return node;
	}

}
